﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SC2parser.Model;
using SC2parser.Parsing;

namespace SC2parser.UserControls.Admin
{
    public partial class AdminOverview : UserControl
    {
        /// <summary>
        /// Usercontrol for the admin.
        /// </summary>
        public AdminOverview()
        {
            InitializeComponent();

            matches = new MatchCollection();
        }
        private GroupStageParser groupParser;
        private BracketParser bracketParser;

        private MatchCollection matches;

        public MatchCollection Matches
        {
            get { return matches; }
            set { matches = value; }
        }

        public event EventHandler MakePollsBtnClicked
        {
            add { btnMakePolls.Click += value; }
            remove { btnMakePolls.Click -= value; }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            flpAdressLines.Controls.Add(new AdressLine());
        }

        private void btnMakePolls_Click(object sender, EventArgs e)
        {
            foreach (AdressLine al in flpAdressLines.Controls)
            {
                if (al.ParserType == Parsing.ParsingType.Groups)
                {
                    groupParser = new GroupStageParser();
                    matches.AddRangeMatches(groupParser.ParseGrupStage(al.InternetAdress));
                }
                if (al.ParserType == Parsing.ParsingType.Bracket)
                {
                    bracketParser = new BracketParser(al.InternetAdress);
                    matches.AddRangeMatches(bracketParser.ParseBracket(al.InternetAdress));
                }
            }
        }

        public class MatchCollection
        {
            private List<Match> listOfMatches;

            public MatchCollection()
            {
                listOfMatches = new List<Match>();
            }

            public void AddMatch(Match m)
            {
                listOfMatches.Add(m);
            }

            public void AddRangeMatches(List<Match> matches)
            {
                listOfMatches.AddRange(matches);
            }

            public IEnumerable<Match> GetMatches()
            {
                foreach (Match m in listOfMatches)
                {
                    yield return m;
                }
            }
        }

        private void adressLine1_Load(object sender, EventArgs e)
        {

        }
    }
}
